﻿using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

using SmlEngine;
using SmlEngine.UI;
//using SmlEngine.UI.Controls.Menus2;
using SmlEngine.UI.Managers;
using SmlEngine.UI.Screens;

namespace Sml.Screens
{
    /// <summary>
    /// Encapsulates a list of sub-elements.
    /// </summary>
    /// <typeparam name="T">Any type.</typeparam>
    public class Element<T>
    {
        /// <summary>
        /// The list of sub-elements.
        /// </summary>
        public List<T> SubElements { get; private set; }
    }

    /// <summary>
    /// Encapsulates and manages a main menu.
    /// </summary>
    public class MainMenuScreen : Screen
    {
        private MenuScene menu;

        public override IEnumerable<string> PreloadedAssets
        {
            get { return new string[] { }; }
        }

        /// <summary>
        /// Constructs a new MainMenuScreen instance.
        /// </summary>
        public MainMenuScreen()
            : base()
        {
            TransitionOnTime = TimeSpan.FromSeconds(2);
            TransitionOffTime = TimeSpan.FromSeconds(2);
        }

        /// <summary>
        /// Initializes this MainMenuScreen.
        /// </summary>
        public override void Initialize()
        {
            menu = new MenuScene(this);
            menu.MenuEntries.Add(new MenuEntry("Single Player", m => ChangeToPlayerMenu()));
            menu.MenuEntries.Add(new MenuEntry("Multiplayer", m => m.Text = "Test"));
            menu.MenuEntries.Add(new MenuEntry("Options", m => m.Text = "Test"));
            menu.MenuEntries.Add(new MenuEntry("Extras", m => m.Text = "Test"));
            menu.MenuEntries.Add(new MenuEntry("Exit", m => ScreenManager.Game.Exit()));
            menu.TransitionOn();
        }


        private void AddCheckedItem(string name)
        {
            int count = menu.MenuEntries.Count;

            menu.MenuEntries.Add(new MenuEntry(name, m =>
            {
                menu.CheckItem(count);
                menu.SelectedColor = Color.Green;
            }));
        }

        private void ChangeToPlayerMenu()
        {
            menu.MenuEntries.Clear();
            menu.MenuEntries.Add(new MenuEntry("Choose this", m => NavigateOff()));
            AddCheckedItem("Two");
            AddCheckedItem("Three");
            menu.SelectedIndex = 0;
        }

        private void NavigateOff()
        {
            ScreenManager.AddScreen(ScreenManager.activeGroupIndex, new TitleScreen());
        }
    }

    /*public class MainMenuScreen : MenuScreen
    {
        public MainMenuScreen()
            : base("Main Menu") { }

        public override void Initialize()
        {
            MenuEntries.Add(new MenuEntry("Single Player", m => { }));
            MenuEntries.Add(new MenuEntry("Single Player", m => { }));
            MenuEntries.Add(new MenuEntry("Single Player", m => { }));
            MenuEntries.Add(new MenuEntry("Single Player", m => { }));
            MenuEntries.Add(new MenuEntry("Single Player", m => { }));
        }

        public override void HandleInput(InputManager input)
        {
            base.HandleInput(input);

            if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.B))
            {

            }
        }
    } */

    /* public class MainMenuScreen : Screen
    {
        public Menu Menu { get; private set; }

        public override void Initialize()
        {
            Menu = new Menu(this);

            Menu.MenuEntries.Add(new MenuEntry("Single Player", m => { }, Menu));
            Menu.MenuEntries.Add(new MenuEntry("Single Player", m => { }, Menu));
            Menu.MenuEntries.Add(new MenuEntry("Single Player", m => { }, Menu));
            Menu.MenuEntries.Add(new MenuEntry("Single Player", m => { }, Menu));
            Menu.MenuEntries.Add(new MenuEntry("Single Player", m => { }, Menu));

            Scenes.Add(Menu);
        }

        public override void HandleInput(InputManager input)
        {
            base.HandleInput(input);

            if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.B))
            {

            }
        }

        public override IEnumerable<string> PreloadedAssets
        {
            get { throw new NotImplementedException(); }
        }
    } */
}
